package dao;

import java.util.ArrayList;

import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import domain.Account;
/**'
 * xml实现dao
 * @author luwz
 *
 */
public class XmlAccountDaoImpl implements IAccountDao {
	@Override
	public List<Account> queryAccountsByUsername(String username) throws DocumentException {
		
		List<Account> list = new ArrayList<Account>();
	    Account account = new Account();
		SAXReader reader= new SAXReader();
		Document document = reader.read("D:\\workspace1\\demo\\crm\\data\\user.xml");
		Element element = (Element) document.selectSingleNode("//user[@name='"+username+"']");
        if (element!=null) {
        	account.setUsername(element.attributeValue("name"));
        	account.setPassword(element.attributeValue("password"));
        	account.setEmail(element.attributeValue("email"));
        	account.setRealName(element.attributeValue("realName"));
        	account.setRoleName(element.attributeValue("roleName"));
        	list.add(account);
		}
		return  list;
	}

}
